import 'package:yp/config/config.dart';
import 'package:yp/services/api.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';

import 'state.dart';

class GoodsCommentLogic extends GetxController {
  final GoodsCommentState state = GoodsCommentState();

  final int pageSize = 15;
  int currentPageNo = 0;
  String styleNumId;

  void requestComment(int pageNo) {
    var params = {
      "use_platform": 2,
      "page_no": pageNo,
      "page_size": pageSize,
      "style_num_id": styleNumId,
      // "shop_id": SpUtil.getInt('storeShopNum'),
      "shop_id": SpUtil.getObject(Config.GET_SHOP_INFO)['shop_id'],
      "traderate_sign": 0 //0默认返回列表，1返回推荐好评的一条
    };
    Api.goodsComments(params).listen((event) {
      state.refreshController.loadComplete();
      if (event['code'] == 0) {
        currentPageNo = pageNo;
        if (pageNo == 1) {
          state.commentList = null;
        }
        List list = event['list'];
        if (list != null && list.isNotEmpty) {
          if (state.commentList == null) {
            state.commentList = [];
          }
          state.commentList.addAll(list);
        }
        if (list == null || list.isEmpty || list.length < pageSize) {
          state.refreshController.loadNoData();
        }
      }
      update();
    });
  }

  void onLoadMoreGoodsList() {}
}
